import UIKit
import Flutter
import UserNotifications
import umeng_push_sdk
import GoogleMaps

@main
@objc class AppDelegate: FlutterAppDelegate{
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      GMSServices.provideAPIKey("AIzaSyDp8bjAsyowDznEExLo57f7d_XSDeaBvzc")
      UMCommonLogManager.setUp()
      UMConfigure.setLogEnabled(true)
      UMConfigure.initWithAppkey("665599058d52370b9d98787a", channel: "APP Store")
    GeneratedPluginRegistrant.register(with: self)
      if #available(iOS 10.0, *) {
          UNUserNotificationCenter.current().delegate = self
      } else {
          // Fallback on earlier versions
      };
      let entity = UMessageRegisterEntity.init();
      entity.types = 7
      UMessage.registerForRemoteNotifications(launchOptions: launchOptions, entity: entity) { granted, error in
          
      }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    @available(iOS 10.0, *)
    override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        if notification.request.trigger is UNPushNotificationTrigger {
            UMessage.setAutoAlert(false)
            UMessage.didReceiveRemoteNotification(userInfo)
            UmengPushSdkPlugin.didReceiveUMessage(userInfo)
        }
        completionHandler([.alert,.sound,.badge]);
    }
    
    @available(iOS 10.0, *)
    override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        if response.notification.request.trigger is UNPushNotificationTrigger {
            UMessage.didReceiveRemoteNotification(userInfo)
            UmengPushSdkPlugin.didOpenUMessage(userInfo) 
        }
       
    }
}
